//
// Created by vcq on 21/2/9.
//
#pragma once
#include "dbng.hpp"
#include "__base_mode__.hpp"
struct goal {
    int id;
    string name;
    string note;
    int _plan_id;
};
REFLECTION(goal, id, name, _plan_id,note)
json MGetGoal(basic_string_view<char> id, basic_string_view<char> _plan_id){
    string sql="select * from `goal` where 1=1 ";
    if (!id.empty()) {
        sql += "and id =";
        sql += id;
    }
    if (!_plan_id.empty()) {
        sql += "and _plan_id =";
        sql += _plan_id;
    }
    Dao dao;
    nlohmann::json article_list,ret,item;
    auto v = dao.query<goal>(sql);
    for (auto& o : v) {
        item["id"]=o.id;
        item["name"]=o.name;
        item["note"]=o.note;
        item["_plan_id"]=o._plan_id;
        article_list.push_back(item);
    }
    ret["code"]=0;
    ret["count"]=article_list.size();
    ret["data"]=article_list;
    return ret;
}
void MAddGoal(const struct goal& goal1){
    Dao dao;
    dao.update_object(goal1);
}
void MDeleteGoal(basic_string_view<char> id){
    MDeleteAll("goal",id);
}